function mad(params, body) {
  const ua = navigator.userAgent.toLowerCase();
  if (ua.match(/ucbrowser/i)) return;
  delete this.list;
  this.list = [];
  if (!body) {
    body = document.body;
  }
  this.body = $(body);//.parent();
  if (Array.isArray(params)) {
    for (let i = 0; i < params.length; i++) {
      this.createObj(params[i], i);
    }
  }
}

mad.prototype.createObj = function (params, i) {
  if (!params.class) params.class = "";
  if (!params.style) params.style = "";
  let f = $(`<div class="gg ${params.class}" style="${params.style}" i=${i}>`);
  let content = $(`<a class="ybl">`);
  let video = false;
  if (params.video) {
    video = $(`<video src="${params.video}" autoplay="autoplay" preload="auto" style="width:100%;">`);
    content.append(video);
  } else {
    if (params.img) content.append(`<img src="${params.img}" style="max-width:100%;max-height:100%">`);
    if (params.audio) content.append(`<audio src="${params.audio}" autoplay="autoplay" preload="auto" loop="loop" style="display:none;">`);
  }
  f.append(content);
  this.list.push({
    start: params.start,
    createFun: params.createFun,
    closeFun: params.closeFun,
    element: f,
    content: content,
    url: params.url,
    first: true
  });
};
mad.prototype.time = function (time) {
  for (let i = 0; i < this.list.length; i++) {
    if (this.list[i].first && time > this.list[i].start) {
      this.list[i].first = false;
      this.show(i, true);
    }
  }
};
mad.prototype.show = function (n, run) {
  if (this.list[n].element) {
    let ec = $(`<div style="position:absolute;top:0px;height:10%;">`);
    ec.append(`<img src="./styles/close.png" style="height:100%;">`);
    ec.click((event) => {
      this.close($(event.target).parents(".gg").attr("i"), true);
      event.stopPropagation();
      return false;
    });
    this.list[n].content.click(() => {
      window.open(this.list[n].url);
    });
    this.list[n].element.append(ec);
    this.body.before(this.list[n].element);
    this.list[n].created = true;
    if (run && this.list[n].createFun) this.list[n].createFun(this.list[n]);
  }
};
mad.prototype.close = function (n, run) {
  if (this.list[n].element) {
    this.list[n].element.children("div").remove();
    this.list[n].element.remove();
    this.list[n].created = false;
    if (run && this.list[n].closeFun) this.list[n].closeFun(this.list[n]);
  }
  // this.body.css("display", "");
};
